using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Weapon_Stat : MonoBehaviour
{
    [SerializeField] private WeaponDataSO _weaponDataSO;
    [SerializeField] private WeaponStatGroup _weaponStatGroup;

    private Player_Stat _playerStat;
    
    public float GetAttackDamage()
    {
        _playerStat = GetComponentInParent<Player_Stat>();
        float critChancePercent = _playerStat.GetCritChance(); //暴击率百分比

        bool isCrit = Random.Range(0, 100) < critChancePercent;
        float baseDmage = _weaponStatGroup.baseDamage.GetValue();

        float critDamage = baseDmage * (1 + _playerStat.GetDamageBouns()) * _playerStat.GetCritPower();
        float normalDamage = baseDmage * (1 + _playerStat.GetDamageBouns());

        return isCrit ? critDamage : normalDamage;
    }
    public float GetMoveSpeed()
    {
        return _weaponStatGroup.bulletSpeed.GetValue();
    }
    [ContextMenu("更新数据")]
    private void AppayDefaultStatSetup()
    {
        if (_weaponDataSO == null)
            return;

        _weaponStatGroup.baseDamage.SetBaseValue(_weaponDataSO.baseDamage);

        _weaponStatGroup.attackRange.SetBaseValue(_weaponDataSO.attackRange);

        _weaponStatGroup.attackSpeed.SetBaseValue(_weaponDataSO.attackSpeed);

        _weaponStatGroup.bulletSpeed.SetBaseValue(_weaponDataSO.bulletSpeed);
    }
}
